<?php 
	$this->display(tpl('head')); 
?>
<style>
	.top_button {
		float: left;
		width: 98%;
		text-align: center;
		padding: 0 1%;
	}
	.top_button a{
		float: left;
		width: 24%;
		padding: 0;
		background-color: #1094FA;
		margin-right: 1%;
		color: #fff;
		padding: 10px 0;
		font-weight: bold;
		border-radius:5px ;
	}
	.wap_sms_list .layui-form-checkbox{
		padding:0 10px;
	}
	.wap_sms_list .wap_sms_list_title{
		line-height: 35px;
		height: 35px;
		overflow: hidden;
	}
	.wap_sms_list .wap_sms_state{
		position: absolute;
		margin-top: 6px;
		right: 0;
		background-color: #fff;
	}
	.wap_sms_list_other{
		float: left;
		width: 100%;
		line-height: 35px;
		color: #838383;
	}
	.wap_sms_list_other_form{
		padding-left: 10px;
	}
	.wap_sms_list_other_form span,.wap_sms_list_other_formtime span{
		padding-right: 10px;
		font-weight: bold;
		
	}
	.wap_sms_list_other_formtime{
		padding-right: 10px;
	}
	.wap_sms_list_action{
		border-top:solid 1px #EFEFEF ;
	}
	.wap_sms_list_action_p{
		position: absolute;
		margin-top: -14px;
		left: 43%;
		font-size: 1.2em;
		background-color: #fff;
	}
	.wap_sms_list_action_button{
		margin-top: 15px;
		margin-bottom: 10px;
		text-align: center;
	}
	.wap_sms_list_action_button .layui-btn{
		font-size: 1em;
		padding: 5px 10px;
		height: 35px;
	}
	.layui-input, .layui-textarea {
		width: 98%;
	}
	.sms_read .layui-input-block{
		line-height: 40px;
	}

</style>
	<div class="w-100 left bcf center">
		<div class="layui-form-item mt10 center top_button">
			<a href="/user/sms/alllist/">所有短信息</a>
			<a href="/user/sms/alllist/read/2">未读短信息</a>
			<a href="/user/sms/alllist/read/1">已读短信息</a>
			<a href="javascript:" lay-submit lay-filter="new_post">发短信</a>
		</div>
	</div>

	<form class="layui-form" method="post" action="/user/sms/del">
			<?php foreach($data AS $row){ ?>
			<div class="wap_sms_list bcf mt10 left w-100" id="list_<?php echo $row[id] ?>">
				<div class="wap_sms_list_title left w-100">
					<input lay-skin="primary" type="checkbox" name="iddb[]" value="<?php echo $row[id] ?>" />
					<?php echo $row[title] ?>
				</div>
				<div class="wap_sms_state" id="state_<?php echo $row[id] ?>">
					<?php if( $row[is_read] ){?>
						<span class="green">【已阅】</span>.
					<?php }else{?>
						<span class="red">【未读】</span>
					<?php } ?>
				</div>
				<div class="wap_sms_list_other  left w-100">
					<div class="wap_sms_list_other_form left">
						<span>发件人:</span><?php echo $row[from_username] ?>
					</div>
					<div class="wap_sms_list_other_formtime right">
						<span>时间:</span><?php echo date('Y-m-d H:i',$row[posttime]) ?>
					</div>
				</div>
				<div class="wap_sms_list_action w-100 left mt10">
					<div class="wap_sms_list_action_p b">操&nbsp;&nbsp;&nbsp;&nbsp;作</div>
					<div class="wap_sms_list_action_button">
						<button lay-submit lay-filter="look"	iid="<?php echo $row[id] ?>" class="layui-btn  layui-btn-xs">查看</button>
						<button lay-submit lay-filter="reply"	uid="<?php echo $row[from_uid] ?>" username="<?php echo $row[from_username] ?>" class="layui-btn  layui-btn-warm layui-btn-xs">回复</button>
						<button lay-submit lay-filter="del"		iid="<?php echo $row[id] ?>" class="layui-btn layui-btn-danger  layui-btn-xs">删除</button>
					</div>
				</div>
			</div>
			<?php } ?>
			
			<?php if($Get_Page) { ?>
			<div class="w-100 left bcf mt10">
				<div class="layui-form-item mt10 center page">
					<?php echo $Get_Page ?>
				</div>
			</div>
			<?php } ?>
			
			
			<div class="w-100 left bcf mt10">
				<div class="layui-form-item mt10 center">
					<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('1')">全选</button>
					<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('-1')">反选</button>
					<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('0')">取消选择</button>
					<button class="layui-btn layui-btn-sm layui-btn-danger">删除</button>
				</div>
			</div>

	</form>
	<div class="sms_read" id="sms_read" style="display: none;">
			<div class="layui-form-item">
				<label class="layui-form-label">短信标题</label>
				<div class="layui-input-block" id="title">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">发送人</label>
				<div class="layui-input-block" id="username">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">短信内容</label>
				<div class="layui-input-block" id="content">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">发送时间</label>
				<div class="layui-input-block" id="time">
				</div>
			</div>
	</div>
	<div class="sms_post" id="sms_post" style="display: none;">
		<div class="layui-form-item mt10">
			<label class="layui-form-label">短信标题</label>
			<div class="layui-input-block">
				<input type="text" name="title" id="post_title" class="layui-input"  placeholder="请输入短信标题"/>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">收件人</label>
			<div class="layui-input-block">
				<input type="text" id="post_username" name="username" class="layui-input" />
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">短信内容</label>
			<div class="layui-input-block">
				<textarea name="content" id="post_content" placeholder="请输入短信内容" class="layui-textarea"></textarea>
			</div>
		</div>
		<div class="layui-form-item mt10 center">
			<input type="hidden" name="uid" id="uid" />
			<button lay-submit lay-filter="post" class="layui-btn">发送</button>
		</div>
	</div>
<script type="text/javascript">
function all_checkbox_check(type){
	if(document.getElementsByClassName('layui-form-checkbox')!=undefined && document.getElementsByClassName('layui-form-checkbox').length>0){  
	  var class_box = document.getElementsByClassName('layui-form-checkbox');
	  var ids = document.getElementsByName('iddb[]');
		if(type=="1"){//全选
			for(var i=0;i<class_box.length;i++){
					$(ids[i]).prop("checked", true);
			   	$(class_box[i]).addClass("layui-form-checked");
			}
		}else if(type=="0"){//全不选
			for(var i=0;i<class_box.length;i++){
					$(ids[i]).prop("checked", false);
			    $(class_box[i]).removeClass("layui-form-checked");
			}
		}else if(type=="-1"){//反选
			for(var i=0;i<class_box.length;i++){
					if(ids[i].checked==true){
						$(ids[i]).prop("checked", false);
					}else{
						$(ids[i]).prop("checked", true);
					}
			   	$(class_box[i]).toggleClass("layui-form-checked");
			}
		}
	}
	return false;
}
layui.use(['form'], function(){
	var form = layui.form;
	//监听提交
	form.on('submit(look)', function(obj){
		var index = layer.load(1, {
		  shade: [0.5,'#000'] //0.1透明度的白色背景
		});
		var iid=obj.elem.attributes.iid.value;
		$.ajax({
			url:"/user/sms/read/",
			type: 'POST',
			data:{'id':iid,'json':true},
			dataType: 'json',
			success: function(data){
				layer.closeAll('loading');
				if(data.code !=0){
					layer.msg(data.text);
					return false;
				}else{
					$("#state_"+iid).html("<span class='green'>【已阅】</span>");
					$("#title").html(data.data.title);
					$("#content").html(data.data.content);
					$("#time").html(data.data.posttime);
					$("#username").html(data.data.from_username);
				}
			}
		})
		layer.open({
			title: '阅读短消息',
			type: 1,
			shadeClose: true,
			skin: 'layui-layer-rim', //加上边框
			area: ['100%'], //宽高
			content: $("#sms_read")
		});
	    return false;
	});
	var close_post='';
	form.on('submit(reply)', function(obj){
		var uid=obj.elem.attributes.uid.value;
		if(uid=='0'){
			//layer.msg("系统信息禁止回复");
			//return false;
		}
		var username=obj.elem.attributes.username.value;
		$("#uid").val(uid);
		$("#post_username").val(username);
		$("#post_username").attr('disabled',true);
	    close_post=layer.open({
			title: '发信息',
			type: 1,
			shadeClose: true,
			area: ['100%'], //宽高
			content: $("#sms_post")
		});
	    return false;
	});
	form.on('submit(new_post)', function(obj){
		$("#uid").val('0');
		$("#post_username").val('');
		$("#post_title").val('');
		$("#post_content").val('');
	    close_post=layer.open({
			title: '发信息',
			type: 1,
			shadeClose: true,
			area: ['100%'], //宽高
			content: $("#sms_post")
		});
	    return false;
	});
	form.on('submit(post)', function(data){
		var index = layer.load(1, {
		  shade: [0.5,'#000'] //0.1透明度的白色背景
		});
		var jsontrue={'json':true};
		c = Object.assign(data.field,jsontrue); 
		$.ajax({
			url:"/user/sms/post/",
			type: 'POST',
			data:c,
			dataType: 'json',
			success: function(data){
				layer.closeAll('loading');
				if(data.code !=0){
					layer.msg(data.text);
					return false;
				}else{
					layer.msg(data.text);
					layer.close(close_post);
					$("#uid").val('');
					$("#post_username").val('');
					$("#post_title").val('');
					$("#post_content").val('');
				}
			}
		})
    	return false;
	})
	form.on('submit(del)', function(obj){
	    var iid=obj.elem.attributes.iid.value;
		$.ajax({
			url:"/user/sms/del/",
			type: 'POST',
			data:{'id':iid,'json':true},
			dataType: 'json',
			success: function(data){
				layer.closeAll('loading');
				if(data.Result==0){
					layer.msg(data.content);
					return false;
				}else{
					$("#list_"+iid).hide("slow");;
				}
			}
		})
	    return false;
	});
})
</script>
<?php 
	$this->display(tpl('foot')); 
?>
